package routers

import (
	"ecomserver/controllers"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/context"
)

func init() {
	beego.InsertFilter("/user/*", beego.BeforeExec, filterFunc)
	//beego.Router("/", &controllers.MainController{})
	beego.Router("/register", &controllers.UserController{}, "get:ShowReg;post:HandleReg")
	beego.Router("/active", &controllers.UserController{}, "get:ActiveReg")
	//用户登陆
	beego.Router("/login", &controllers.UserController{}, "get:ShowLogin;post:HandleLogin")
	//跳转到首页
	beego.Router("/", &controllers.GoodsController{}, "get:ShowIndex")
	//退出登陆
	beego.Router("/user/logout", &controllers.UserController{}, "get:Logout")
	//用户中心信息页
	beego.Router("/user/center_info", &controllers.UserController{}, "get:ShowUserCenter")
	//全部订单
	beego.Router("/user/center_order", &controllers.UserController{}, "get:ShowUserCenterOrder")
	//收货地址
	beego.Router("/user/center_site", &controllers.UserController{}, "get:ShowUserCenterSite;post:HandleUserCenterSite")
	//商品详情展示
	beego.Router("/goodsDetail", &controllers.GoodsController{}, "get:ShowGoodsDetail")
	//商品列表页
	beego.Router("/goodsList", &controllers.GoodsController{}, "get:ShowList")
	//搜索
	beego.Router("/goodsSearch", &controllers.GoodsController{}, "post:HandleSearch")
	//购物车添加
	beego.Router("/user/addCart", &controllers.CartController{}, "post:HandleAddCart")
	//展示购物车页面
	beego.Router("/user/cart", &controllers.CartController{}, "get:ShowCart")
	//更新购物车
	beego.Router("/user/updateCart", &controllers.CartController{}, "post:UpdateCart")
	//删除购物车
	beego.Router("/user/deleteCart", &controllers.CartController{}, "post:DeleteCart")
	//展示订单
	beego.Router("/user/showOrder", &controllers.OrderController{}, "post:ShowOrder")
	//添加订单
	beego.Router("/user/addOrder", &controllers.OrderController{}, "post:AddOrder")
}

//user过滤器
var filterFunc = func(ctx *context.Context) {
	username := ctx.Input.Session("username")
	if username == nil {
		ctx.Redirect(302, "/login")
		return
	}
}
